using System;
using System.Collections;
using System.Collections.Generic;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
using Microsoft.Xna.Framework.Content;

using System.Xml;

namespace TimeWar.Objects
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public abstract class ActiveGameObject : Microsoft.Xna.Framework.GameComponent
    {
        protected string propertyFile;
        protected ArrayList childGameObjects;
        protected string name;
        protected Texture2D primaryGraphic;
        protected string primaryGraphicLocation;
        protected Vector2 currLocation;
        protected GameCursor currCursor;

        public void setPropertyFile(string file_path)
        {
            propertyFile = file_path;
        }

        public ActiveGameObject(Game game)
            : base(game)
        {
            // TODO: Construct any child components here

        }

        public void setName(string obj)
        {
            name = obj;
        }

        public string getName()
        {
            return name;
        }

        public void setPrimaryGraphicLocation(string fileLocation)
        {
            primaryGraphicLocation = fileLocation;
        }

        public void setCurrLocation(float x, float y)
        {
            currLocation.X = x;
            currLocation.Y = y;
        }

        public void setGameCursor(GameCursor obj)
        {
            currCursor = obj;
        }


        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        public abstract void Draw(GraphicsDeviceManager graphics, GameTime gameTime, SpriteBatch gameSpriteBatch);
        public abstract void LoadContent(GraphicsDevice graphicsDevice);

        public bool isCursorOverObject()
        {
            bool answer = false;
            Vector2 currCursorLocation = currCursor.getCurrLocation();

            if (currCursorLocation.X > (currLocation.X - (primaryGraphic.Width / 2)))
            {
                if (currCursorLocation.X < (currLocation.X + (primaryGraphic.Width / 2)))
                {
                    if (currCursorLocation.Y > (currLocation.Y - (primaryGraphic.Height / 2)))
                    {
                        if (currCursorLocation.Y < (currLocation.Y + (primaryGraphic.Height / 2)))
                        {
                            answer = true;
                        }
                    }
                }
            }

            return answer;



        }

        public bool isObjClicked()
        {
            bool answer = false;
            bool bttnClicked = false;

#if PC

            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                bttnClicked = true;
            }
#endif

            if (GamePad.GetState(PlayerIndex.One).Buttons.A == ButtonState.Pressed)
            {
                bttnClicked = true;
            }

            if (isCursorOverObject() && bttnClicked)
            {
                answer = true;
            }


            return answer;

        }

    }
}